package com.xcy.goatmilk.util;

import java.util.*;

/**
 * @author xcy
 * @date 2019/9/19 10:28
 * @description 集合操作工具类
 * @since V1.0.0
 */
public class CollectionsUtils {

    private CollectionsUtils() {

    }

    /**
     * 将map转成list,并且按照key进行排序
     * @param map 注意:此处的map结构为Map(String, Integer)还没将此方法扩展成通用//TODO 将map转list工具类改造成通用
     * @return
     */
    public static List mapToListAndSortByKey(Map map) {
        List list = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o1.getKey().compareTo(o2.getKey());
            }
        });
        return list;
    }


}
